export const mixList = {
  data() {
    return {
      pageOption: {
        pageNum: 1,
        pageSize: 10,
      },
      status: 'loadmore',
      pages: 0,
      total: 0,
      list: [],
    };
  },
  onPullDownRefresh() {

    this.pageOption = {
      pageNum: 1,
      pageSize: 10,
    };
    this.getList(true);
    setTimeout(function() {
      uni.stopPullDownRefresh();
    }, 1000);
  },
  onReachBottom() {
    if (this.pageOption.pageNum < this.pages) {
      this.pageOption.pageNum++
      this.getList()
    } else {
      this.status = 'nomore'
    }

  },
  methods: {
    mixList(res, isRefresh = false) {
      if (isRefresh) {
        this.list = res.list;
      } else {
        this.pages = res.pages;
        this.total = res.total;
        this.list = this.list.concat(res.list);
      }

      // return res
    },
    // 加载数据
    async loadMore() {
      if (this.isLoading || !this.hasMore) {
        return;
      }
      this.isLoading = true;
      const res = await fetchData(this.pageNo, this.pageSize);
      this.list = this.list.concat(res.data);
      this.pageNo++;
      this.isLoading = false;
      this.hasMore = res.hasMore;
    }
  }
}

